package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.SysRoleMapper;
import com.atguigu.spzx.manager.service.SysRoleService;
import com.atguigu.spzx.model.dto.system.SysRoleDto;
import com.atguigu.spzx.model.entity.system.SysRole;
import com.github.pagehelper.IPage;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class SysRoleServiceImpl implements SysRoleService {

    @Autowired
    SysRoleMapper sysRoleMapper;

    @Override
    public PageInfo<SysRole> findPage(SysRoleDto sysRoleDto, Integer pageNum, Integer pageSize) {

        PageHelper.startPage(pageNum,pageSize); //将两个参数封装为Page对象，将Page对象与当前线程进行绑定。

        List<SysRole> list =  sysRoleMapper.findPage(sysRoleDto);

        return new PageInfo<SysRole>(list);
    }


    @Override
    public void save(SysRole sysRole) {
        sysRoleMapper.insert(sysRole);
    }

    @Override
    public SysRole getById(Long id) {
        return sysRoleMapper.getById(id);
    }

    @Override
    public void update(SysRole sysRole) {
        sysRoleMapper.update(sysRole);
    }

    @Override
    public void deleteById(Long id) {
        sysRoleMapper.deleteById(id);
    }
}
